import sys
import uuid

from loguru import logger

logger.remove()
Logger = logger

Logger.add(
    sys.stdout,
    format='{time:YYYY-MM-DD HH:mm:ss}\t|{level}\t|{file}:{line}\t|{extra[thread_id]}\t|{message}',
    enqueue=True,  # 安全队列-启用
    level='INFO',  # 日志等级-INFO
    diagnose=True  # 变量值-显示
)

Logger = Logger.bind(thread_id='common')


def thread_logger(thread_id=None):
    tid = 'common'
    if thread_id:
        tid = str(uuid.uuid4())[:8]
    tl = Logger.bind(thread_id=tid)
    return tl


if __name__ == '__main__':
    try:
        1 / 0
    except Exception as e:
        Logger.exception('An error occurred: {}', e)
        sys.exit()

    print('test')